package java_0220.leetcode;

/**
 * 判断二叉树是否是对称二叉树
 */
public class Num101_SymmetricTree {
    public boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return isMirror(root.left,root.right);//判断左右子树是否镜像

    }

    /**
     * 判断left和right这两棵树是否镜像相等
     * @param left
     * @param right
     * @return
     */
    private boolean isMirror(TreeNode left, TreeNode right) {
        if(left==null&&right==null){
            return true;
        }
        if(left==null||right==null){
            return false;
        }
        if(left.val!=right.val){
            return false;
        }
        //left的左树要和right的右树镜像相等&&left的右树要和right的左树镜像相等
        return isMirror(left.left,right.right)&&isMirror(left.right,right.left);
    }
}
